package com.test.jfreechart;

import java.awt.Font;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;

@SuppressWarnings("serial")
public class JFreeChartTest2 extends ApplicationFrame
{
     public JFreeChartTest2	(String title)
     { 
    	 //constructor
    	 super(title);
    	 this.setContentPane(createPanel());
     }
	public static CategoryDataset createDataset(){
		DefaultCategoryDataset dcd = new DefaultCategoryDataset();
		dcd.setValue(10, "", "manager");
		dcd.setValue(20, "", "salesman");
		dcd.setValue(40, "", "developer");
		dcd.setValue(15, "", "others");
		return dcd;
	}
	public static JFreeChart createChart(CategoryDataset dcd){
		JFreeChart chart = ChartFactory.createBarChart("resource", "distribution of staff", "number of staff", dcd, 
				PlotOrientation.VERTICAL, true, false, false);
		chart.setTitle(new TextTitle("human resource",new Font("宋体",Font.BOLD+Font.ITALIC,12))); //修改 title
		CategoryPlot plot = (CategoryPlot)chart.getCategoryPlot();
		CategoryAxis categoryAxis = plot.getDomainAxis();
		categoryAxis.setLabelFont(new Font("宋体",Font.BOLD+Font.ITALIC,8));
		return chart;
	}
	
	public static JPanel createPanel(){
		JFreeChart chart =createChart(createDataset());
		return new ChartPanel(chart);
	}
	public static void main(String[] args) {	
		JFreeChartTest2 chart = new JFreeChartTest2("human resource");
	    chart.pack();
	    chart.setVisible(true);
}
}
